{{ define "admin/access/add.html" }}
{{ template "layouts/header.html" }}
<body style="background-color: #FFFFFF">
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-inline">
            <select name="module_id" lay-verify="required"  lay-search="">
                <option value="0">顶级菜单</option>
                {{ range $key,$value := .accessList }}
                <option value="{{$value.Id}}">{{$value.Name}}</option>
                {{range $k,$v := $value.Children}}
                <option value="{{$v.Id}}"> ---- {{$v.Name}}</option>
                {{ end }}
                {{ end }}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-inline">
            <input type="text" name="module_name" lay-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">URL地址</label>
        <div class="layui-input-inline">
            <input type="text" name="url" lay-verify="required" placeholder="请输入URL地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-inline">
            <input type="text" name="icon" id="iconPicker"   value=""   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否显示</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-verify="required" lay-filter="status" name="status" value="1" lay-skin="switch" lay-text="开启|关闭" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单类型</label>
        <div class="layui-input-inline" style="width: 50%">
            <input type="radio" name="type" value="1" title="菜单" checked>
            <input type="radio" name="type" value="2" title="接口">
            <input type="radio" name="type" value="3" title="按钮">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="number" name="sort"  placeholder="请输入排序" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-inline">
            <textarea name="description" style="width: 400px; height: 150px;" autocomplete="off" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="layuiadmin-app-form-submit" value="确认添加">
    </div>
</div>
<script>
    layui.use(['layer','index','form','iconPicker'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,iconPicker=layui.iconPicker;

        //图标选择器
        iconPicker.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // 数据类型：fontClass/unicode，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function(d) {
                console.log(d);
            }
        });

        //事件-提交
        form.on('submit(submit)', function(data){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url:"/admin/access/doadd",
                method: "POST",
                data: data.field,
                success: function(res) {
                    if(res.code == 0){
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1500,
                        },function () {
                            // parent.layui.table.reload('table-index'); //重载表格
                            window.parent.location.reload(); //刷新父页面
                            parent.layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 1500
                        });
                    }
                },
                error: function() {
                    layer.msg("添加失败");
                }
            });
        });

        /* 事件-指定开关 */
        form.on('switch(status)', function(obj){
            obj.elem.value = this.checked ? 1 : 0
            form.render();
        });
    })
</script>
</body>
{{ end }}